home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS01.ADF / C / echox.c < prev    next >
C/C++ Source or Header  |  1985-11-15  |  2KB  |  84 lines

  1. /* expand.doc, echox.c */
  2.  
  3.  
  4. #ifdef FOOIE
  5.  
  6. The file EXPAND.O is the object for a group of subroutines which
  7. expand wild card filenames for AMIGA DOS.  The wild card syntax
  8. is similar to unix and implements *, ? and [] type syntax e.g.
  9.  
  10.  
  11.         *.c             /* anything ending in .c */
  12.         ???.a?          /* anything beginning with any three characters,
  13.                            followed by a . followed by 'a' followed by
  14.                            any single character */
  15.  
  16.         *.[ch]          /* anything ending in .c or .h */
  17.  
  18. There are two routines:
  19.  
  20. First:
  21.  
  22.         int iswild(p)
  23.         char *p;        returns true if the string pointed to by p
  24.                         contains *, ? or [
  25.  
  26. Second:
  27.  
  28.   struct args
  29.     {
  30.         int argcount;
  31.         char **argvector;
  32.     } *ap,*expand();
  33.  
  34.    struct args *expand(p)
  35.    char *p;             returns a pointer to a structure as shown above
  36.                         containing a list of all the matching names.
  37.  
  38.                         Note: the names may contain full paths but the
  39.                         last specifier is file names only.  e.g. if
  40.                         you pass:
  41.  
  42.                                 a/b/c/* this will work but none of
  43.                                 the directories in c will be found
  44.  
  45.                                 a/b/*/* does not work!
  46.  
  47. These routines are available on object form only.  
  48.  
  49. Good luck,
  50. the folks at Tardis Software!
  51.  
  52. #endif
  53.  
  54. /* echox.c */
  55.  
  56. main(argc,argv)
  57. int argc;
  58. char **argv;
  59. {
  60.   int i,j;
  61.  
  62.   struct args
  63.     {
  64.         int argcount;
  65.         char **argvector;
  66.     } *ap,*expand();
  67.  
  68.   i = 1;
  69.   while(--argc)
  70.     {
  71.       printf("argv[%d] = \"%s\"\n",i,argv[i]);
  72.       if (iswild(argv[i]))
  73.         {
  74.           ap = expand(argv[i]);
  75.           printf("ap -> argcount = %d\n",ap -> argcount);
  76.           printf("ap -> argvector = %x\n",ap->argvector);
  77.           for(j=0; j < ap ->argcount; j++)
  78.             printf("argvector[%d]=\"%s\"\n",j,ap->argvector[j]);
  79.         }
  80.       i++;
  81.     }
  82. }
  83.  
  84.